/*
* Copyright @2009-2012 www.happyelements.com, all rights reserved.
* Create date: 2012-7-27
* Piggy Dong
* 董文弈
* wenyi.dong@happyelements.com
*/
package com.happyelements.isolib
{
	import flash.geom.Point;

	/**
	 * @author dongpiggyi
	 */
	public class IsoUtil
	{
		private static const COS:Number = Math.cos(Math.PI / 4) * 0.5;

		public static function isoToScene(isoX:Number, isoY:Number):Point
		{
			var result:Point = new Point();

			result.x = IsoUtil.COS * 2 * (isoX - isoY);
			result.y = IsoUtil.COS * (isoY + isoX);

			result.x = Number(result.x.toFixed(2));
			result.y = Number(result.y.toFixed(2));

			return result;
		}

		public static function sceneToIso(scenePosition:Point):Point
		{
			return null;
		}

		public static function rowColumnToScene(rowIndex:int, columnIndex:int):Point
		{
			var result:Point = new Point();

			result.x = (rowIndex - columnIndex) * IsoWorld.instance.tileWidth / 2;
			result.y = (columnIndex + rowIndex) * IsoWorld.instance.tileHeight / 2;

			return result;
		}

		public static function sceneToRowColumn(x:Number, y:Number):Point
		{
			var result:Point = new Point();

			result.x = x / IsoWorld.instance.tileWidth + y / IsoWorld.instance.tileHeight;
			result.y = y / IsoWorld.instance.tileHeight - x / IsoWorld.instance.tileWidth;

			result.x = Math.floor(result.x);
			result.y = Math.floor(result.y);

			return result;
		}
	}
}
